package com.service.zy;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.dao.zy.ProductClassifyDao;
import com.dao.zy.ProductClassifyMybatisDao;
import com.entity.ProductClassify;
import com.service.ServiceException;

@Service
@Transactional(rollbackFor=ServiceException.class)
public class ProductClassifyService {
	@Autowired
	private ProductClassifyDao productclassifyDao;
	@Autowired
	private ProductClassifyMybatisDao productclassifymybatisDao;
	
	/**
	 * 添加类别
	 * @param pc
	 * @throws ServiceException
	 */
	public void add(ProductClassify pc) throws ServiceException {
		try {
			productclassifyDao.save(pc);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 删除类别
	 * @param id
	 * @throws ServiceException 
	 */
	public void delOne(Long id) throws ServiceException {
		try {
			productclassifyDao.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 查询所有类别
	 * @return
	 * @throws ServiceException
	 */
	public List<ProductClassify> findAll() throws ServiceException{
		try {
			return (List<ProductClassify>) productclassifyDao.findAll();
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 查询一个类别
	 * @param id
	 * @return
	 * @throws ServiceException
	 */
	public ProductClassify findOne(Long id) throws ServiceException {
		try {
			ProductClassify pc = productclassifyDao.findOne(id);
			System.out.println(pc.getName());
			return pc;
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 剪切操作
	 * @param id
	 * @return
	 * @throws ServiceException
	 */
	public ProductClassify cut(Long id) throws ServiceException{
		try {
			ProductClassify pc = productclassifyDao.findOne(id);		//剪切的类别id
			return pc;
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
	/**
	 * 粘贴操作
	 * @throws ServiceException
	 */
	public void paste(ProductClassify pc,Long id) throws ServiceException {
		try {
			pc.setSuperid(id);
			productclassifyDao.save(pc);
		}catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e);
		}
	}
}
